﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web.UI;
using OpenWaves.Web.Controls;

namespace OpenWaves.Web.Tests
{
    public partial class Default : Page
    {
        protected override void OnLoad(EventArgs e)
        {
            this.components.DataSource = this.GetTestItems();
            this.components.DataBind();
        }

        private IEnumerable<ShowcaseItem> GetTestItems()
        {
            foreach (string test in Directory.GetFiles(Server.MapPath("."), "*Tests.aspx"))
                yield return new ShowcaseItem
                {
                    Title = Path.GetFileNameWithoutExtension(test).SplitCamelCase(),
                    Identifier = Path.GetFileNameWithoutExtension(test),
                    ExampleUrl = Path.GetFileName(test),
                    Markup = File.ReadAllText(test).Trim(),
                    CodeBehind = File.ReadAllText(Path.ChangeExtension(test, "aspx.cs"))
                };
        }
    }

    public class ShowcaseItem
    {
        public string Title { get; set; }
        public string ExampleUrl { get; set; }
        public string Markup { get; set; }
        public string CodeBehind { get; set; }
        public string Identifier { get; set; }
    }

    public class ShowcaseItemRepeater : Repeater<ShowcaseItem>
    {
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [TemplateContainer(typeof(RepeaterItem<ShowcaseItem>))]
        public new ITemplate ItemTemplate
        {
            get { return base.ItemTemplate; }
            set { base.ItemTemplate = value; }
        }
    }
}